﻿<UserControl x:Class="Waf.MusicManager.Presentation.Views.PlayerView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:p="clr-namespace:Waf.MusicManager.Presentation.Properties"
             xmlns:ctrl="clr-namespace:Waf.MusicManager.Presentation.Controls"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:dd="clr-namespace:Waf.MusicManager.Presentation.DesignData"
             mc:Ignorable="d" d:DataContext="{d:DesignInstance dd:SamplePlayerViewModel, IsDesignTimeCreatable=True}"
             d:DesignWidth="800" Height="58" Background="{DynamicResource {x:Static SystemColors.ControlBrushKey}}">
    <Grid Margin="10,5,5,7">
        <Grid.Resources>
            <Style TargetType="TextBlock" BasedOn="{StaticResource {x:Type TextBlock}}">
                <Setter Property="VerticalAlignment" Value="Center"/>
            </Style>
        </Grid.Resources>
        
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition/>
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="150"/>
            <ColumnDefinition Width="20"/>
            <ColumnDefinition Width="Auto"/>
            <ColumnDefinition Width="*"/>
            <ColumnDefinition Width="Auto"/>
            <ColumnDefinition Width="30"/>
            <ColumnDefinition Width="Auto"/>
            <ColumnDefinition Width="Auto"/>
            <ColumnDefinition Width="Auto"/>
            <ColumnDefinition Width="20"/>
            <ColumnDefinition Width="Auto"/>
            <ColumnDefinition Width="Auto"/>
        </Grid.ColumnDefinitions>

        <TextBlock Text="{Binding PlaylistManager.CurrentItem.MusicFile.Metadata.Artists, Converter={StaticResource StringListToStringConverter}, ConverterParameter=ListSeparator}" 
                   TextTrimming="CharacterEllipsis" Grid.Row="0" Grid.Column="0" ctrl:ToolTipBehavior.AutoToolTip="True"/>
        <TextBlock TextTrimming="CharacterEllipsis" Grid.Row="1" Grid.Column="0" ctrl:ToolTipBehavior.AutoToolTip="True">
            <TextBlock.Text>
                <MultiBinding Converter="{StaticResource MusicTitleConverter}">
                    <Binding Path="PlaylistManager.CurrentItem.MusicFile.FileName"/>
                    <Binding Path="PlaylistManager.CurrentItem.MusicFile.Metadata.Artists"/>
                    <Binding Path="PlaylistManager.CurrentItem.MusicFile.Metadata.Title"/>
                </MultiBinding>
            </TextBlock.Text>
        </TextBlock>

        <Slider x:Name="positionSlider" LargeChange="30" SmallChange="5"
                Margin="4" Grid.Column="2" Grid.ColumnSpan="3" ValueChanged="PositionSliderValueChanged" MouseWheel="PositionSliderMouseWheel">
            <Slider.Style>
                <Style TargetType="Slider" BasedOn="{StaticResource {x:Type Slider}}">
                    <Style.Triggers>
                        <DataTrigger Binding="{Binding PlaylistManager.CurrentItem.MusicFile}" Value="{x:Null}">
                            <Setter Property="Visibility" Value="Collapsed"/>
                        </DataTrigger>
                    </Style.Triggers>
                </Style>
            </Slider.Style>
        </Slider>
        <TextBlock x:Name="positionLabel" Text="0:00" Grid.Row="1" Grid.Column="2">
            <TextBlock.Style>
                <Style TargetType="TextBlock" BasedOn="{StaticResource {x:Type TextBlock}}">
                    <Style.Triggers>
                        <DataTrigger Binding="{Binding PlaylistManager.CurrentItem.MusicFile}" Value="{x:Null}">
                            <Setter Property="Visibility" Value="Collapsed"/>
                        </DataTrigger>
                    </Style.Triggers>
                </Style>
            </TextBlock.Style>
        </TextBlock>
        <TextBlock Text="{Binding PlaylistManager.CurrentItem.MusicFile.Metadata.Duration, Converter={StaticResource DurationConverter}}" Grid.Row="1" Grid.Column="4"/>

        <Button Command="{Binding PlayerService.PreviousCommand}" Content="&#xE100;" Style="{StaticResource IconButtonStyle}" Grid.RowSpan="2" Grid.Column="6"/>
        <Button Command="{Binding PlayerService.PlayPauseCommand}" Grid.RowSpan="2" Grid.Column="7">
            <Button.Style>
                <Style TargetType="Button" BasedOn="{StaticResource IconButtonStyle}">
                    <Setter Property="Content" Value="&#xE102;"/>
                    <Style.Triggers>
                        <DataTrigger Binding="{Binding PlayerService.IsPlayCommand}" Value="False">
                            <Setter Property="Content" Value="&#xE103;"/>
                        </DataTrigger>
                    </Style.Triggers>
                </Style>
            </Button.Style>
        </Button>
        <Button Command="{Binding PlayerService.NextCommand}" Content="&#xE101;" Style="{StaticResource IconButtonStyle}" Grid.RowSpan="2" Grid.Column="8"/>

        <Button x:Name="volumeButton" Click="VolumeButtonClick" Content="&#xE15D;" Style="{StaticResource IconButtonStyle}" Grid.RowSpan="2" Grid.Column="10"/>
        <ctrl:Flyout x:Name="volumePopup" PlacementTarget="{Binding ElementName=volumeButton}"
               Placement="Top" HorizontalFlyoutAlignment="Center" VerticalOffset="-10">
            <Border BorderBrush="{StaticResource DefaultBorderBrush}" BorderThickness="1" Background="{StaticResource DarkBackground}">
                <Grid Margin="5,10,5,15">
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto"/>
                        <RowDefinition Height="10"/>
                        <RowDefinition Height="Auto"/>
                    </Grid.RowDefinitions>

                    <Button x:Name="muteButton" Click="ToggleMuteClick" Content="&#xE15D;" Style="{StaticResource IconButtonStyle}" Grid.Row="0"/>
                    <Slider x:Name="volumeSlider" Value="{Binding Volume}" Maximum="1" LargeChange="0.1" SmallChange="0.01" 
                            Orientation="Vertical" HorizontalAlignment="Center" Height="200" Grid.Row="2" MouseWheel="VolumeSliderMouseWheel"/>
                </Grid>
            </Border>
        </ctrl:Flyout>
        
        <Button x:Name="moreButton" Click="MoreButtonClick" Content="&#xE10C;" Style="{StaticResource IconButtonStyle}" Grid.RowSpan="2" Grid.Column="11"/>
        <ctrl:Flyout x:Name="morePopup" PlacementTarget="{Binding ElementName=moreButton}" Placement="Top" HorizontalFlyoutAlignment="Right" VerticalOffset="-10">
            <Border BorderBrush="{StaticResource DefaultBorderBrush}" BorderThickness="1" Background="{StaticResource DarkBackground}">
                <Grid Margin="5,10,5,5" Width="245">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="80"/>
                        <ColumnDefinition Width="85"/>
                        <ColumnDefinition Width="80"/>
                    </Grid.ColumnDefinitions>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto"/>
                        <RowDefinition Height="Auto"/>
                    </Grid.RowDefinitions>

                    <ToggleButton IsChecked="{Binding PlaylistManager.Shuffle}" Content="&#xE14B;" Style="{StaticResource IconToggleButtonStyle}" Grid.Column="0"/>
                    <TextBlock Grid.Row="1">
                        <TextBlock.Style>
                            <Style TargetType="TextBlock" BasedOn="{StaticResource AppBarTextBlockStyle}">
                                <Setter Property="Text" Value="{x:Static p:Resources.ShuffleOff}"/>
                                <Style.Triggers>
                                    <DataTrigger Binding="{Binding PlaylistManager.Shuffle}" Value="True">
                                        <Setter Property="Text" Value="{x:Static p:Resources.ShuffleOn}"/>
                                    </DataTrigger>
                                </Style.Triggers>
                            </Style>
                        </TextBlock.Style>
                    </TextBlock>

                    <ToggleButton IsChecked="{Binding PlaylistManager.Repeat}" Content="&#xE1CD;" Style="{StaticResource IconToggleButtonStyle}" Grid.Column="1"/>
                    <TextBlock Grid.Row="1" Grid.Column="1">
                        <TextBlock.Style>
                            <Style TargetType="TextBlock" BasedOn="{StaticResource AppBarTextBlockStyle}">
                                <Setter Property="Text" Value="{x:Static p:Resources.RepeatOff}"/>
                                <Style.Triggers>
                                    <DataTrigger Binding="{Binding PlaylistManager.Repeat}" Value="True">
                                        <Setter Property="Text" Value="{x:Static p:Resources.RepeatOn}"/>
                                    </DataTrigger>
                                </Style.Triggers>
                            </Style>
                        </TextBlock.Style>
                    </TextBlock>

                    <Button Command="{Binding InfoCommand}" Content="&#xE2C0;" Style="{StaticResource IconButtonStyle}" Grid.Column="2"/>
                    <TextBlock Text="{x:Static p:Resources.Info}" Style="{StaticResource AppBarTextBlockStyle}" Grid.Row="1" Grid.Column="2"/>
                </Grid>
            </Border>
        </ctrl:Flyout>
    </Grid>
</UserControl>
